package cn.dapeng.rpc.common.serial;


import cn.dapeng.rpc.common.exception.UnSupportSerializeException;

public class SerializeFactory {

    public synchronized static byte[] serial(Object object, int serialType) throws Exception {

        return switch (serialType) {
            case 0:
                yield JDKSerializeCoder.serial(object);
            case 1:
                yield KryoSerializerCoder.serial(object);
            default:
                throw new UnSupportSerializeException(serialType);
        };

    }

    public synchronized static <T> T deseria(byte[] bytes, Class<T> clazz, int serialType) throws Exception {
        return switch (serialType) {
            case 0:
                yield JDKSerializeCoder.deseria(bytes, clazz);
            case 1:
                yield KryoSerializerCoder.deseria(bytes, clazz);
            default:
                throw new UnSupportSerializeException(serialType);
        };
    }
}
